package v1

import (
	"github.com/gin-gonic/gin"
	"io/ioutil"
	"net/http"
)

type Student struct {
	Name string `json:"name"`
	ID   uint64 `json:"id"`
}

func PING(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"message": "everything is ok",
	})
}

func JsonBind(c *gin.Context) {
	var s Student
	_ = c.ShouldBindJSON(&s)

	c.JSON(http.StatusOK, gin.H{
		"student": s,
		"message": "你刚刚发送的信息",
	})
}

func PingPost(c *gin.Context) {
	s, err := ioutil.ReadAll(c.Request.Body)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"msg": "之川你好，我们的服务器发送了未知错误",
		})
	}
	c.Writer.Write(s)
}
